﻿using Language.Resource;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Ms;

namespace VisionCloud.Api.Controllers.Ms
{
    /// <summary>
    /// 日志模块
    /// </summary>
    [SystemModuleAttribute("日志模块")]
    [ApiVersion("1.0")]
    [Route("api/ms/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "日志模块")]
    public class FmsController : ApiBaseController
    {
        /// <summary>
        /// 日志服务
        /// </summary>
        public MsLogService MsLogService { get; set; }

        /// <summary>
        /// 多语言资源
        /// </summary>
        public IStringLocalizer<ControllerResource> localizer { get; set; }

        /// <summary>
        /// 上传日志文件
        /// </summary>
        /// <param name="formCollection">deviceGuid:设备序列号 type:visionCloud=后台日志;visionFramework=框架日志</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> UploadLog(IFormCollection formCollection)
        {
            if (formCollection.Files.Count > 0)
            {
                var deviceGuid = formCollection["deviceGuid"];
                var type = formCollection["type"];
                return await TryCatchAsync(MsLogService.UploadLog(deviceGuid, type, formCollection.Files[0])).ConfigureAwait(false);
            }
            return ApiResult.Error(localizer["YB0007"].Value);  //new ApiResult(AjaxCode.Error, localizer["YB0007"].Value);
        }
    }
}